package com.example.bai12;

import com.example.object.ChucVu;
import com.example.object.NhanVien;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;

public class ThemNhanVienActivity extends Activity {

	Button btnhuy,btnluu;
	EditText edtmanv,edttennv;
	RadioButton rdbnam;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.them_nhan_vien);
		getControls();
		addEvents();
	}
	
	private void getControls()
	{
		btnhuy= (Button) findViewById(R.id.btnhuy);
		btnluu= (Button) findViewById(R.id.btnluu);
		edtmanv= (EditText) findViewById(R.id.edtmanv);
		edttennv= (EditText) findViewById(R.id.edttennv);
		rdbnam= (RadioButton) findViewById(R.id.rdnam);
	}
	private void addEvents()
	{
		btnhuy.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				proccessXoa();
			}
		});
		btnluu.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				proccessLuu();
			}
		});
	}
	private void proccessXoa()
	{
		edtmanv.setText("");
		edttennv.setText("");
		edtmanv.requestFocus();
	}
	
	private void proccessLuu()
	{
		String id= edtmanv.getText().toString();
		String nm= edttennv.getText().toString();
		NhanVien nv= new NhanVien(id, nm);
		nv.setChucvu(ChucVu.NhanVien);
		nv.setGioitinh(!rdbnam.isChecked());
		Intent i= getIntent();
		Bundle b= new Bundle();
		b.putSerializable("NHANVIEN", nv);
		i.putExtra("DATA", b);
		setResult(MainActivity.THEM_NV_THANH_CONG, i);
		finish();
	}
	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenuInfo menuInfo) {
		// TODO Auto-generated method stub
		super.onCreateContextMenu(menu, v, menuInfo);
	}

}
